package cn.itsource.base.controller;

import cn.itsource.base.util.AjaxResult;
import cn.itsource.base.util.FastdfsUtil;
import cn.itsource.base.util.UploadResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.sound.midi.Soundbank;
import java.io.IOException;

@RestController
@RequestMapping("/file")
public class FileController {
    @PostMapping("/upload")
    public AjaxResult upload(@RequestBody MultipartFile file) throws IOException {
        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
        String upload = FastdfsUtil.upload(file.getBytes(), suffix);
        String uploadUrl = "http://47.95.117.210:8888"+upload;
        return AjaxResult.me().setResultObj(new UploadResult(upload,uploadUrl));
    }
}
